home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- CMovie.c
-
- The Movie Class
-
- Displays a standard QuickTime Movie.
-
- This is a read-only class that allows you to specify and play a QuickTime
- movie with minimal other features. It is designed to simply allow the
- importation and display of movie files. The movies are controlled by
- the standard movie controller.
-
- This class could be expanded to allow editing and more…
-
- SUPERCLASS = CPane
-
- Copyright © 1992 Joe Zobkiw. All rights reserved.
- Portions Copyright © 1990 Symantec Corporation. All rights reserved.
-
- ******************************************************************************/
-
- #include "CMovie.h"
- #include "CCollaborator.h"
- #include "CEBCollaborator.h"
- #include "Defines.h"
- #include <Commands.h>
- #include <Global.h>
- #include <CPaneBorder.h>
- #include <TCLUtilities.h>
- #include <TBUtilities.h>
-
- extern CEBCollaborator *gEBCollaborator;
-
- /******************************************************************************
- IMovie
-
- Initialize a Movie object
- ******************************************************************************/
-
- void CMovie::IMovie(
- CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- FSSpec *movieSpec)
- {
-
- CPane::IPane(anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing);
-
- //
- // we want to receive clicks
- //
-
- SetWantsClicks(true);
-
- //
- // we want a simple border in case we decide to resize the frame to be
- // smaller than it’s enclosure. this will make it look nicer.
- //
-
- itsBorder = new(CPaneBorder);
- itsBorder->IPaneBorder(kBorderFrame);
-
- //
- // initialize our instance variables
- //
-
- movie = NULL;
- movieRefNum = 0;
- controller = NULL;
-
- //
- // we want be a gopher!
- //
-
- SetCanBeGopher(true);
- BecomeGopher(true);
-
- //
- // we want to recieve events from gEBCollaborator which is our provider…
- // the one whom we depend upon
- //
-
- DependUpon(gEBCollaborator);
-
- //
- // if we have a movie to open (the user selected Open… instead of New) then
- // open the movie!
- //
-
- if (movieSpec != NULL)
- ImportMovie(movieSpec);
- }
-
- /******************************************************************************
- Dispose (OVERRIDE)
-
- Dispose of a Movie object
- ******************************************************************************/
-
- void CMovie::Dispose()
- {
- ForgetInstanceVariables();
- CancelDependency(gEBCollaborator);
- inherited::Dispose();
- }
-
- /******************************************************************************
- ProviderChanged
-
- Our Provider has changed
- ******************************************************************************/
-
- void CMovie::ProviderChanged( CCollaborator *aProvider, long reason, void* info)
- {
- switch(reason) {
-
- //
- // kEventRecordReason is the only reason we deal with these days
- //
-
- case kEventRecordReason: {
-
- short eventHandled;
-
- //
- // we might end up drawing because of this MCPlayer event
- // so we must be sure our port is set up correctly.
- //
-
- Prepare();
-
- //
- // see if the movie controller would like the event or not
- //
-
- eventHandled = MCIsPlayerEvent(controller, (EventRecord*)info);
- if (eventHandled == true) {
-
- //
- // we handled the event so we change it to a null event
- // so it is (in effect) ignored elsewhere.
- //
-
- ((EventRecord*)info)->what = nullEvent;
- }
-
- }
- break;
-
- default:
- break;
- }
-
- inherited::ProviderChanged(aProvider, reason, info);
- }
-
- /******************************************************************************
- DoClick (OVERRIDE)
-
- This will get called if we click outside of the movie but still
- within the Movie Pane (which is currently sticky to the size of the window)
- ******************************************************************************/
-
- void CMovie::DoClick(Point hitPt, short modifierKeys, long when)
- {
- //
- // this alert will beep the first two times and show itself the third time
- // and thereafter. It will simply remind the user that clicking in the empty
- // area of the CMovie Pane is fruitless other than showing this annoying alert.
- //
-
- if (active)
- NoteAlert(kMovieDoClickALRT, nil);
- }
-
- /******************************************************************************
- ImportMovie
-
- Use the movie pointed to by spec as our movie. This routine imports
- the given movie, replacing any previous movies that were used in this pane.
-
- ******************************************************************************/
- void CMovie::ImportMovie(FSSpec *spec)
- {
- Rect movieRect;
- Boolean locked;
-
- //
- // hop out if there is no spec to import
- //
-
- if (spec == NULL) return;
-
- //
- // lock ourselves down and prepare for drawing, etc.
- //
-
- locked = Lock(true);
- Prepare();
-
- //
- // forget our current movie & controller, if we have them
- //
-
- ForgetInstanceVariables();
-
- //
- // open the movie file and create a new movie from the file
- //
-
- FailOSErr(OpenMovieFile(spec, &movieRefNum, fsRdPerm));
- FailOSErr(NewMovieFromFile(&movie, movieRefNum, nil, nil, newMovieActive, nil));
-
- //
- // get the bounds for the movie and make sure the top left is 0,0
- // so the movie won't be offset within the window
- //
-
- GetMovieBox(movie, &movieRect);
- FailOSErr(GetMoviesError());
- OffsetRect(&movieRect,-movieRect.left,-movieRect.top);
- SetMovieBox(movie, &movieRect);
- FailOSErr(GetMoviesError());
-
- //
- // rewind the movie
- //
-
- GoToBeginningOfMovie(movie);
- FailOSErr(GetMoviesError());
-
- //
- // create our controller
- //
-
- controller = NewMovieController(movie, &movieRect, mcWithFrame+mcTopLeftMovie);
- FailOSErr(GetMoviesError());
-
- //
- // redraw ourselves
- //
-
- Refresh();
-
- //
- // reset our locked state
- //
-
- Lock(locked);
- }
-
-
- /******************************************************************************
- Dawdle {OVERRIDE}
-
- Call MoviesTask here if we have a movie and it is playing. MoviesTask()
- handles updating the movie for us. It will update the movie in the background
- also.
-
- ******************************************************************************/
-
- void CMovie::Dawdle(long *maxSleep)
- {
- if (movie != NULL) {
- if (!IsMovieDone(movie)) {
- Prepare(); // get ready to draw
- MoviesTask(movie, 0); // update the movie
- FailOSErr(GetMoviesError()); // check the error condition
- }
- }
- }
-
-
- /******************************************************************************
- Draw {OVERRIDE}
-
- Draw a Movie and the controller if need be.
-
- ******************************************************************************/
-
- void CMovie::Draw(Rect *area)
- {
- Rect tempRect;
-
- //
- // prepare to draw
- //
-
- Prepare();
-
- //
- // draw our movie or fill the pane with gray pattern if we have no movie
- //
-
- if (movie == NULL) {
- LongToQDRect( &aperture, &tempRect);
- FillRect(&tempRect, &gray);
- } else {
- UpdateMovie(movie); // update the movie next time MoviesTask is called
- FailOSErr(GetMoviesError()); // check for errors
- MoviesTask(movie, 0); // actually perform the update
- FailOSErr(GetMoviesError()); // check for errors
- }
-
- //
- // if we have a controller, draw it here
- //
-
- if (controller != NULL) {
- MCDraw(controller, GetMacPort());
- }
- }
-
- /******************************************************************************
- ForgetInstanceVariables
-
- clears the instance variables of this class
- ******************************************************************************/
- void CMovie::ForgetInstanceVariables(void)
- {
- if (movie != NULL) {
- DisposeMovie(movie);
- movie = NULL;
- }
- if (movieRefNum != 0) {
- CloseMovieFile(movieRefNum);
- movieRefNum = 0;
- }
- if (controller != NULL) {
- DisposeMovieController(controller);
- controller = NULL;
- }
- }